<?php

include('inc/init.php');

$smarty->template_dir = 'templates';
$smarty->assign('title', $title);

$sql = "select t1.id, t1.title, t1.isspecialoffer, t1.monthstart, t1.monthend, t1.yearstart, t1.yearend, t2.country
        from ats_package t1 inner join ats_destination t2 
        on t1.`dest_id`=t2.id";
$package = $db->prepare($sql);
$package->execute();
$package->setFetchMode(PDO::FETCH_ASSOC);

$smarty->assign('package', $package);

$data = array();
$i = 0;
foreach ($package as $p) {
    $row = array();
    $row["id"] = $p['id'];
    $row["title"] = $p['title'];
    $row["isspecialoffer"] = ($p['isspecialoffer'] == 1) ? true: false;

    $timestamp = mktime(0, 0, 0, $p['monthstart']);
    $startmonth_s = date("M", $timestamp);
    $row["start"] = $startmonth_s . "-" . $p['yearstart'];
    
    $timestamp = mktime(0, 0, 0, $p['monthend']);
    $endmonth_s = date("M", $timestamp);
    $row["end"] = $endmonth_s . "-" . $p['yearend'];
    
    $row["destination"] = $p['country'];
    $data[$i] = $row;
    $i++;
}
header("Content-type: application/json");
echo "{\"data\":" . json_encode($data) . "}";
?>